// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import SaveManager from "../../Managers/SaveManager";
import MapManager from "../../Models/Maps/MapManager";
import MapTemplate from "../../Models/Maps/MapTemplate";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MapItem extends cc.Component {
    @property(cc.Label)
    nameTxt: cc.Label = null;
    @property(cc.Label)
    txt0: cc.Label = null;
    @property(cc.Label)
    txt1: cc.Label = null;
    @property(cc.Button)
    selectBtn: cc.Button = null;
    @property(cc.Toggle)
    bgToggle: cc.Toggle = null;
    @property(cc.Toggle)
    iconToggle: cc.Toggle = null;

    mapTp: MapTemplate;
    drawItem(tp: MapTemplate) {

        this.mapTp = tp;
        this.nameTxt.string = this.mapTp.mapName;
        this.txt0.string = "敌人生命 +" + this.mapTp.enemyHpAdd + "%。";
        this.txt1.string = "金币获取 +" + this.mapTp.goldAdd + "%。";
        this.selectBtn.node.active = SaveManager.single.userdata.currentMapId != tp.id;
        this.iconToggle.isChecked = this.bgToggle.isChecked = SaveManager.single.userdata.currentMapId == tp.id;
    }

    selectClick() {
        MapManager.single.requestSelectMap(this.mapTp.id);
    }

}
